package com.thinkcube.edutainment.adapters;

import java.util.List;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.thinkcube.edutainment.domain.data.GlossaryData;
import com.thinkcube.edutainment.service.viewitem.GlossaryItem;
import com.thinkcube.edutainment.service.viewitem.GlossaryItem_;

@EBean
public class GlossaryAdapter extends BaseAdapter {

	List<GlossaryData> glossaryData;

	@RootContext
	Context context;

	@Override
	public View getView(final int position, final View convertView,
			final ViewGroup parent) {

		GlossaryItem glossaryItem;
		if (convertView == null) {
			glossaryItem = GlossaryItem_.build(context);
		} else {
			glossaryItem = (GlossaryItem) convertView;
		}

		glossaryItem.bind(getItem(position));

		return glossaryItem;
	}

	public List<GlossaryData> getGlossaryData() {
		return glossaryData;
	}

	public void setGlossaryData(List<GlossaryData> glossaryData) {
		this.glossaryData = glossaryData;
	}

	@Override
	public int getCount() {
		return glossaryData.size();
	}

	@Override
	public GlossaryData getItem(final int position) {
		return glossaryData.get(position);
	}

	@Override
	public long getItemId(final int position) {
		return position;
	}

}
